<?php

class Jobs_model extends MY_Model {

    public function __construct() {
        parent::__construct();
        $this->table = 'jg_jobs';
    }

    public function frontend_records($limit = 0, $offset = 0, $conditions = array()) {
        $lang = $this->input->cookie('lang') == 'en' ? '_en' : '';
        $select_string = "j.id as id ,j.position{$lang} as position,j.requirements{$lang} as requirements";
        $this->db->select($select_string);
        $this->db->from($this->table . ' j');

        if (isset($conditions[0])) {
            foreach ($conditions as $condition) {
                $this->db->where($condition[0], $condition[1]);
            }
        }
        if ($limit) {
            $this->db->limit($limit, $offset);
        }
        
        $this->db->order_by('j.created_at','desc');

        $query = $this->db->get();
        return $query->result();
    }

    public function frontend_find($id) {
        $lang = $this->input->cookie('lang') == 'en' ? '_en' : '';
        $select_string = "j.id as id ,j.position{$lang} as position,j.requirements{$lang} as requirements";
        $this->db->select($select_string);
        $this->db->from($this->table . ' j');
        $this->db->where('j.id', $id);
        $this->db->limit(1);
        $query = $this->db->get();
        return $query->row_object();
    }

}
